<li class="tree-node">
    <div class="node-content">
        @if(isset($node['children'] ))
            <span class="toggle-icon">▶</span>
        @else
            <span class="toggle-icon" style="visibility: hidden;">•</span>
        @endif

        <span class="node-title">

{{$node['id']}} &nbsp;【{{ $node['name'] }}】{{ $node['Level'] }} &nbsp;拼单数: {{ $node['GroupOrderCount']??0 }}

<small class="text-muted">(电话: {{ $node['telephone'] }})</small>
            <a href="javascript:void(0);" class="grid-column-copyable text-muted copyFn" data-content="{{ $node['telephone'] }}" title="电话已复制"
               data-placement="bottom">
    <i class="fa fa-copy"></i>
</a>
{{--            <span class="badge badge-info ml-2">{{ $node['children']  }}人</span>--}}
</span>

        {{--        <div class="ml-auto">--}}
        {{--            <a href="{{ admin_url("departments/{$node['id']}/subtree") }}"--}}
        {{--               class="btn btn-xs btn-primary"--}}
        {{--               title="查看子树">--}}
        {{--                <i class="fa fa-sitemap"></i>--}}
        {{--            </a>--}}
        {{--            <a href="{{ admin_url("users?department_id={$node['id']}") }}"--}}
        {{--               class="btn btn-xs btn-info"--}}
        {{--               title="查看成员">--}}
        {{--                <i class="fa fa-users"></i>--}}
        {{--            </a>--}}
        {{--        </div>--}}
    </div>

    @if(isset($node['children']))
        <ul>
            @foreach($node['children'] as $child)
                @include('node', [
                    'node'  => $child,
                    'level' => $level + 1
                ])
            @endforeach
        </ul>
        {{--    @elseif($node->_rgt - $node->_lft > 1)--}}
        {{--        <div class="load-more"--}}
        {{--             data-id="{{ $node->id }}"--}}
        {{--             onclick="loadChildren(this)">--}}
        {{--            加载更多...--}}
        {{--        </div>--}}
    @endif
</li>

{{--@push('scripts')--}}
<script>

    Dcat.ready(function () {
        // const $target = $(element);
        // const id = $target.data('id');
        //
        // $target.html('<span class="loading"></span>');
        $('.copyFn').off('click.dynamic').on('click.dynamic', function(v) {
            copyToClipboard($(this).data('content'))
            Dcat.swal.info('电话已复制');
            v.stopPropagation();
        });

        function copyToClipboard(text) {
            if (navigator.clipboard) {
                navigator.clipboard.writeText(text).then(function() {
                    Dcat.swal.info('电话已复制');
                }).catch(function(err) {
                    Dcat.swal.info("复制失败: " + err);
                });
            } else {
                var $temp = $("<textarea>");
                $("body").append($temp);
                $temp.val(text).select();
                try {
                    var success = document.execCommand("copy");
                    if (success) {
                        Dcat.swal.info("复制成功！");
                    } else {
                        Dcat.swal.info("复制失败");
                    }
                } catch (err) {
                    Dcat.swal.info("复制错误: " + err);
                }
                $temp.remove();
            }
        }
        {{--$.ajax({--}}
        {{--    url: '/admin/api/' + id + '/children',--}}
        {{--    data: {level: {{ $level ?? 0 }}},--}}
        {{--    success: function (res) {--}}
        {{--        $target.replaceWith(res);--}}
        {{--    }--}}
        {{--});--}}
    })
</script>
{{--@endpush--}}
